﻿using System.Collections.ObjectModel;
using System.Drawing;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Prism.Events;
using Prism.Mvvm;
using SoonCode.Core;
using SoonCode.FocusTest.Models;
using SoonCode.FocusTest.Utils;

namespace SoonCode.FocusTest.ViewModels
{
    public class TestPrintViewModel:BindableBase
    {
        private string _title;
        private TestPrintModel _model;
        private BitmapImage? _qrcode;
        private string _printFoot;

        public BitmapImage? QRCode
        {
            get { return _qrcode; }
            set
            {
                _qrcode = value;
                RaisePropertyChanged();
            }
        }
        public string Title
        {
            get { return _title;}
            set
            {
                _title= value;
                RaisePropertyChanged();
            } }

        public TestPrintModel Model
        {
            get { return _model;}
            set
            {
                _model = value;
                RaisePropertyChanged();
            }
        }

        public string PrintFoot
        {
            get { return _printFoot; }
            set
            {
                _printFoot=value;
                RaisePropertyChanged();
            }
        }
        private IEventAggregator aggregator;

        public TestPrintViewModel(IEventAggregator aggregator)
        {
            this.aggregator = aggregator;
        }

        public void SetData(TestPrintModel info)
        {
            OrgInfo org = GlobalModel.Instance.OrgInfo;
            Title = org.c_name.IsNullOrEmpty()? org.name:org.c_name;
            Model= info;
            Bitmap image= QRCodeUtil.GenerateQRCodeBitmap("http://focus.xinshengcorp.com/device/report.html?id="+info.PID);
            QRCode = QRCodeUtil.BitmapToImageSource(image);
            PrintFoot = org.c_printFoot;
        }

    }
}
